How to: Create a query to calculate a sum or other total for all fields.
Solution:
Create a select query, make sure the 'Totals' row is displayed, and select the desired function from the 'Total' drop-down list.
1) If the Database window is not active, activate the Database window.
2) Create a select query:
a) Click the 'Queries' tab in the Database window.
Queries tab
b) Click 'New'. (The New Query dialog box appears.)
c) Select 'Design View' from the list box.
d) Click 'OK'. (The new query opens in Design view, with the Show Table dialog box open.)
e) Do one of the following:
1] Click the 'Tables' tab to list tables only.
2] Click the 'Queries' tab to list queries only.
3] Click the 'Both' tab to list both tables and queries.
f) Select the tables and/or queries to use for the new query.
NOTE: To select more than one adjacent table/query, press and hold down SHIFT while selecting the tables/queries. To select more than one nonadjacent table/query, press and hold down CTRL while selecting the tables/queries.
g) Click 'Add'. (The selected tables and queries appear in the Query Design window behind the Show Table dialog box.)
h) Click 'Close' to close the 'Show Table' dialog box.
i) If there are multiple tables in the query, they must be joined together by defining relationships:
NOTE: If there are default relationships already defined between any of the tables, Access automatically displays their join lines. Access also can automatically create joins between two fields with the same name and data type in two different tables (but only if one of the fields is a primary key).
1] Click on the primary key field in one table.
2] Drag the primary key field from that table on top of the foreign key field of the table to which it is to be joined.
NOTE: The foreign key field in the second table must be the same data type as the primary key field in the first table.
3] Release the mouse button. (A join line appears from the first table to the second table, with a '1' at the first table and an infinity sign at the second table, designating a one-to-many relationship.)
j) Add fields to the query:
1] Select a field from a table's field list in the top half of the Query Design window.
2] Drag the field to the desired column of the design grid in the bottom half of the Query Design window.
Design grid
3] Release the mouse button. (The field name appears in the Field row, and its table appears in the Table row.)
Field row and Table row
4] Repeat steps 2)j)1] through 2)j)3] for each field to add to the query.
NOTE: Fields can also be added to the query by selecting a field from the drop-down list box in the 'Field' row of the design grid in the bottom half of the Query Design window.
Design grid
3) Select the 'View' menu and select 'Totals'. (The Totals row appears in the query design grid.)
Totals row
4) Click in the 'Total' row for the first field for which to calculate a total. (A down arrow appears.)
5) Click on the arrow. (A drop-down list appears.)
6) Select the desired function from the 'Total' drop-down list.
NOTE: The choices are 'Group By', 'Sum', 'Avg', 'Min', 'Max', 'Count', 'StDev', 'Var', 'First', 'Last', 'Expression', and 'Where'.
7) Select the 'File' menu and select 'Save' to save the query. (The Save As dialog box appears.)
8) Type a name for the query in the 'Query Name' box.
9) Click 'OK'. (The query just created is saved.)
10) To view the results of the query just created, select the 'View' menu and select 'Datasheet'.